package com.huangwei.socketchat.server;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class ServerSocketStart {
    private static final int port = 5463;
    private ExecutorService executorService;

    public static void main(String[] args) throws IOException {
        new ServerSocketStart().startServer(port);
    }

    public void startServer(int port) throws IOException {
        ServerSocket serverSocket = new ServerSocket(port);
        executorService = Executors.newCachedThreadPool();
        while (true) {
            System.out.println("等待用户连接...");
            Socket socket = serverSocket.accept();
            ServerSocketThread serverSocketThread = new ServerSocketThread(socket);
            executorService.submit(serverSocketThread::clientMessageListenner);
        }
    }
}
